#include <stdio.h>

int atoi(char *s)
{
    int result = 0;
    int sign = 1;
    while(*s != '-' && (*s < '0' || *s > '9'))
        s++;

    if(*s == '\0')
    {
        return 0;
    }

    if(*s == '-')
        sign = -1;

    while(*s != '\0')
    {
        if(*s >= '0' && *s <= '9')
            result = result * 10 + *s - '0';
        s++;
    }
    return result;
}

int main()
{
    //字符串转整型
    char s[] = "      -102";
    printf("%d\n", atoi(s));
    return 0;
}